package cn.zmwh.im.server.mq.handler;

import cn.zmwh.im.common.pojo.dto.IMRecvInfo;
import cn.zmwh.im.server.constant.IMRedisKey;
import cn.zmwh.im.server.netty.processor.MessageProcessorGroup;
import cn.zmwh.im.server.netty.processor.MessageProcessorPrivate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MessageSendHandlerConfig {


    /**
     * 群聊推送
     * @param processor
     * @return
     */
    @Bean("groupHandler")
    public MessageSendHandler groupHandler(MessageProcessorGroup processor) {
        return new MessageSendHandler() {

            @Override
            public String getQueue() {
                return IMRedisKey.IM_MESSAGE_GROUP_QUEUE;
            }

            @Override
            public void onMessage(IMRecvInfo recvInfo) {
                processor.send(recvInfo);
            }
        };
    }

    /**
     * 私聊推送
     * @param processor
     * @return
     */
    @Bean("privateHandler")
    public MessageSendHandler privateHandler(MessageProcessorGroup processor) {
        return new MessageSendHandler() {
            @Override
            public String getQueue() {
                return IMRedisKey.IM_MESSAGE_PRIVATE_QUEUE;
            }

            @Override
            public void onMessage(IMRecvInfo recvInfo) {
                processor.send(recvInfo);
            }
        };
    }

    /**
     * 系统推送
     * @param processor
     * @return
     */
    @Bean("systemHandler")
    public MessageSendHandler systemHandler(MessageProcessorGroup processor) {
        return new MessageSendHandler() {
            @Override
            public String getQueue() {
                return IMRedisKey.IM_MESSAGE_SYSTEM_QUEUE;
            }

            @Override
            public void onMessage(IMRecvInfo recvInfo) {
                processor.send(recvInfo);
            }
        };
    }



    /**
     * 私聊重试
     * @param processor
     * @return
     */
    @Bean("reissueGroupHandler")
    public MessageSendHandler reissuePrivateHandler(MessageProcessorPrivate processor) {
        return new MessageSendHandler() {
            @Override
            public String getQueue() {
                return IMRedisKey.IM_MESSAGE_REISSUE_QUEUE;
            }

            @Override
            public void onMessage(IMRecvInfo recvInfo) {
                processor.send(recvInfo);
            }
        };
    }

    /**
     * 群聊重试
     * @param processor
     * @return
     */
    @Bean("reissueGroupHandler")
    public MessageSendHandler reissueGroupHandler(MessageProcessorGroup processor) {
        return new MessageSendHandler() {
            @Override
            public String getQueue() {
                return IMRedisKey.IM_MESSAGE_REISSUE_GROUP_QUEUE;
            }

            @Override
            public void onMessage(IMRecvInfo recvInfo) {
                processor.send(recvInfo);
            }
        };
    }
}
